'''
'''
import pickle
from keras import backend as K
from keras import models
import numpy as np
import json    
import random

def UtilizeDFmodel(packet_sequence):
    # 使用训练好的DF模型进行预测
    # 输出倒数第二层作为输出
    '''
    v = LoadPklData()
    v = v.astype('float32')
    v = v[:, :,np.newaxis]
    print(v.shape[0], "training samples")
    '''
    #y = np_utils.to_categorical(y, nb_classes=10)
    model = models.load_model("../df-master/saved_trained_models/ClosedWorld_DF_NoDef.h5")
    
    # 将列表裁剪为5000长度，转换为np.array
    for item in packet_sequence:
        if len(item) > 5000:
            item = item[:5000]
        elif len(item) < 5000:
            item.extend([0] * (5000 - len(item)))

    v = np.array(packet_sequence)
    # print(v.shape)

    # 输入的应该为三维数组
    v = v.astype('float32')
    v = v[:, :,np.newaxis]

    # print(v.shape[0], "training samples")
    
    layer_out = model.predict(v)
    # print(layer_out)
    # print("The layer_out has length of %d" %(len(layer_out)))
    return layer_out

if __name__ == '__main__':
    packet_sequence = []
    for i in range(3):
        random_sequence = [random.choice([1, -1]) for _ in range(random.randint(1, 5000))]
        packet_sequence.append(random_sequence)
    vector = UtilizeDFmodel(packet_sequence)
    #print(vector.shape)
    #print(vector)